from rest_framework import serializers
from .models import Course


class CourseListSerializer(serializers.ModelSerializer):
    class Meta:
        model = Course
        fields = ('__all__')


class CourseListDetailSerializer(serializers.ModelSerializer):
    class Meta:
        model = Course
        fields = ('__all__')



    article_list = serializers.SerializerMethodField()


    def get_article_list(self,id):
        course_articles = list()
        print("id type:",type(id))

        articles = Course.objects.get(pk=id.id).article_set.order_by('course_sequence')
        print("pk:", id)



        for article in articles:

            article_detail = {"id":article.id,"title":article.title,"content":article.body,}
            course_articles.append(article_detail)
        return course_articles




# Course.objects.get(pk=id).article_set.order_by('course_sequence')